from django.shortcuts import render, HttpResponse
import random
from utils.tencent.sms import send_sms_single
from s25 import settings

def send_sms(requests):
    """发送短信
        ?tpl = login ->登录模板的id
        ?tpl = register -> 注册模板的id
    """
    tpl = requests.GET.get('tpl')
    template_id = settings.TENCENT_SMS_TEMPLATE.get(tpl)
    if not template_id:
        return HttpResponse('模板不存在')
    code = random.randrange(1000, 9999)
    res = send_sms_single('17854724133', 2173902, [code, ])
    print(res)
    return HttpResponse('成功')